package cn.fintecher.pangolin.service.dataimp.task;

import cn.fintecher.pangolin.common.model.UserModel;
import cn.fintecher.pangolin.common.utils.ZWDateUtil;
import cn.fintecher.pangolin.entity.elastic.PreRecord;
import cn.fintecher.pangolin.entity.elastic.PreRecordModel;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;

/**
 * @Auther: xiaqun
 * @Description:
 * @Date: 15:16 2019/11/5
 */

@Service("confirmPreFuture")
public class ConfirmPreFuture {
    /**
     * 多线程确认
     */
    @Async
    public CompletableFuture<List<PreRecord>> processPreRecord(List<PreRecordModel> list, UserModel userModel) {
        List<PreRecord> preRecords = new ArrayList<>();
        for (PreRecordModel preRecordModel : list) {
            PreRecord preRecord = new PreRecord();
            preRecord.setId(preRecordModel.getId()); //主键ID
            preRecord.setBatchNumber(preRecordModel.getBatchNumber()); //批次号
            preRecord.setCertificateNo(preRecordModel.getCertificateNo()); //身份证号
            preRecord.setContent(preRecordModel.getContent()); //催记内容
            preRecord.setDate(preRecordModel.getDate()); //催记时间
            preRecord.setPrincipalId(preRecordModel.getPrincipalId()); //委托方ID
            preRecord.setPrincipalName(preRecordModel.getPrincipalName()); //委托方名称
            preRecord.process(userModel.getRealName(), userModel.getId(), ZWDateUtil.getNowDateTime());
            preRecords.add(preRecord);
        }
        return CompletableFuture.completedFuture(preRecords);
    }
}
